﻿using System.Collections.Generic;
using System.Linq;
using INSE6260.OnlineBanking.Model.Payee;
using INSE6260.OnlineBanking.Infrastructure;

namespace INSE6260.OnlineBanking.Repository.EF.Repositories
{
    public class PayeeRepository : RepositoryBase<Payee>,IPayeeRepository
    {
        public PayeeRepository(IUnitOfWork unitOfWork): base(unitOfWork)
        {
            
        }

        public List<Payee> GetClientPayee(int clientId)
        {
            return SourceQuery.Where(p => p.ClientId == clientId).ToList();
        }

        public string GetPayeeName(int payeeId)
        {
            var payee = SourceQuery.FirstOrDefault(p => p.Id == payeeId);
            return payee != null ? payee.NickName : string.Empty;
        }

        public Payee GetPayeeById(int payeeId)
        {
            return FindByID(payeeId);
        }

        public void CreatePayee(Payee payee)
        {
            Add(payee);
            SaveChanges();
        }


        public void EditPayee(Payee payee)
        {
            Update(payee);
            SaveChanges();
        }

        public void DeletePayee(Payee payee)
        {
            Remove(payee);
            SaveChanges();
        }
    }
}
